package com.googlecode.sampleapp.ex01;

import org.drools.KnowledgeBase;
import org.drools.runtime.StatefulKnowledgeSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class InfoServiceImpl implements InfoService {
	@Autowired
	KnowledgeBase sampleKBase;
	
	public void getInfo1() {
		StatefulKnowledgeSession sampleKSession = sampleKBase.newStatefulKnowledgeSession();
		
		System.out.println("Task #1: " + sampleKSession);
		Product p = new Product("meat", 7, 50.00);
		sampleKSession.insert(p);
		p = new Product("cheese", 12, 7.00);
		sampleKSession.insert(p);
		
		Store s = new Store("Morning Store", "Morning Street");
		sampleKSession.insert(s);
		s = new Store("Jump Store", "Jump Street");
		sampleKSession.insert(s);
		
		sampleKSession.startProcess("sampleProcess");
		sampleKSession.fireAllRules();
		sampleKSession.dispose();
		sampleKSession = null;
	}
	
	@Override
	public void getInfo2() {
		StatefulKnowledgeSession sampleKSession = sampleKBase.newStatefulKnowledgeSession();
		
		System.out.println("Task #2: " + sampleKSession);
		
		Product p = new Product("syrup", 55, 33.00);
		sampleKSession.insert(p);
		p = new Product("milk", 33, 44.00);
		sampleKSession.insert(p);
		
		Store s = new Store("Afternoon Store", "Dash Street");
		sampleKSession.insert(s);
		s = new Store("Dash Store", "Dash Street");
		sampleKSession.insert(s);
		
		sampleKSession.startProcess("sampleProcess");
		sampleKSession.fireAllRules();
		sampleKSession.dispose();
		sampleKSession = null;
	}
	
	@Override
	public void getInfo3() {
		StatefulKnowledgeSession sampleKSession = sampleKBase.newStatefulKnowledgeSession();
		System.out.println("Task #3: " + sampleKSession);
		
		Product p = new Product("candy", 12, 9.00);
		sampleKSession.insert(p);
		p = new Product("popcorn", 11, 5.00);
		sampleKSession.insert(p);
		
		Store s = new Store("Midnight Store", "Midnight Street");
		sampleKSession.insert(s);
		s = new Store("Flying Store", "Flying Street");
		sampleKSession.insert(s);
		
		sampleKSession.startProcess("sampleProcess");
		sampleKSession.fireAllRules();
		sampleKSession.dispose();
		sampleKSession = null;
	}
}
